<template>
	<div class="main-container page-fixed">
		<main-content :title="contentTitle">
			<div slot="search">
				<div class="search-box">
					<el-input v-model="searchParam.Keyword" size="small"
						:placeholder="$t('searchModule.searchPlaceholder')" style="width: 200px; margin-right:5px;">
					</el-input>
					<el-button type="primary" icon="el-icon-search" size="small" @click="searchUser">
						{{$t('searchModule.searchBtn')}}</el-button>
					<el-button icon="el-icon-refresh" size="small" @click="searchReset">
						{{$t('searchModule.searchReset')}}</el-button>
				</div>
			</div>
			<div slot="table">
				<avue-crud ref="cuTable" :data="companiesUser" :option="option" stripe :page.sync="page"
					:showColumn="showColumn" :isSaveColumns="true" @on-load="onPageLoad" @sort-change="sortChange"
					@row-click="handleCurrentRowChange" @row-dblclick="handleRowDBLClick">
					<template slot="menuLeft">
						<el-button type="primary" icon="el-icon-plus" size="small" v-if="hasButtonPermission('add')"
							@click="openForm()">{{$t('buttonModule.addBtn')}}
						</el-button>
						<el-button size="small" v-if="hasButtonPermission('disabled')" @click="disableUser">
							{{$t('orgUserManagement.disUserBtn')}}</el-button>
						<el-button size="small" @click="enableUser" v-if="hasButtonPermission('enabled')">
							{{$t('orgUserManagement.enUserBtn')}}</el-button>
						<el-button size="small" @click="resetPassword" v-if="hasButtonPermission('resetpassword')">
							{{$t('orgUserManagement.resetPasswordBtn')}}</el-button>
						<el-button size="small" v-if="hasButtonPermission('authorizeapp')"
							@click="openAppAuthorizeDialog">APP功能授权</el-button>
						<el-button size="small" @click="setAuthorize" v-if="hasButtonPermission('authorize')">
							{{$t('orgUserManagement.setAuthorizeBtn')}}</el-button>
						<OrgImport type="user"></OrgImport>
					</template>
					<template slot="menu" slot-scope="scope">
						<el-button type="opr-primary" size="mini" v-if="hasButtonPermission('modify')"
							@click="editForm(scope.row)">{{$t('tableOperationModule.editorBtn')}}</el-button>
						<el-button type="opr-danger" size="mini" @click="deleteForm"
							v-if="hasButtonPermission('delete')">{{$t('tableOperationModule.deleteBtn')}}</el-button>
						<!--<el-button
              type="danger"
              size="mini"
              v-if="hasButtonPermission('delete')"
              @click="deleteForm"
              >删除</el-button
            >-->
					</template>
				</avue-crud>
			</div>
		</main-content>
		<!-- APP功能授权 -->
		<AppAuthorize v-if="appAuthorizeVisible" @close="appAuthorizeVisible=false" :objectType="objectType"
			:objectId="objectId"></AppAuthorize>
		<!--新增 编辑 -->
		<el-dialog v-dialogDrag :title="$t('orgUserManagement.addModal.modalTitle')" :append-to-body="true"
			:visible.sync="dialogVisible" :close-on-click-modal="false" width="80%" :before-close="handleClose" style="margin-top: -100px;">
			<div class="companiesuser-form custom-form" v-if="dialogVisible">
				<el-form :rules="rules" ref="userForm" :model="companiesUserForm" label-width="80px">
					<el-col :span="24">
					  <el-form-item label-width="0" prop="field1037fb3">
					    <h2 align='center' style="color:undefined;font-size: 16px;text-align: left"
					      :style="{width: '100%'}">账户信息</h2>
					  </el-form-item>
					</el-col>
					<el-col :span="12" v-show="hasFormPermission('F_Account')">
						<el-form-item prop="F_Account" :label="$t('orgUserManagement.addModal.labelAccount')">
							<el-input :placeholder="$t('orgUserManagement.addModal.placeholderAccount')" size="small"
								v-model="companiesUserForm.F_Account"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" v-show="hasFormPermission('F_Telephone')">
						<el-form-item prop="F_Telephone" label="手机号">
							<el-input placeholder="请输入手机号" size="small"
								v-model="companiesUserForm.F_Telephone"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" v-show="hasFormPermission('F_Password')">
						<el-form-item prop="F_Password" :label="$t('orgUserManagement.addModal.labelPassword')"
							v-if="flag">
							<el-input type="password"
								:placeholder="$t('orgUserManagement.addModal.placeholderPassword')" size="small"
								v-model="companiesUserForm.F_Password"></el-input>
						</el-form-item>
						<el-form-item :label="$t('orgUserManagement.addModal.labelPassword')" v-else>
							<el-input :placeholder="$t('orgUserManagement.addModal.placeholderPassword')" size="small"
								:value="'******'" :disabled="true"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
					  <el-form-item label-width="0" prop="field104168b">
					    <h2 align='center' style="color:undefined;font-size: 16px;text-align: left"
					      :style="{width: '100%'}">企业信息</h2>
					  </el-form-item>
					</el-col>
					<el-col :span="12" v-show="hasFormPermission('F_FirmName')">
					  <el-form-item :label="$t('企业名称')" prop="F_FirmName">
					    <el-input v-model="companiesUserForm.F_FirmName" placeholder="请输入企业名称" size="small">
					    </el-input>
					  </el-form-item>
					</el-col>
					<el-col :span="12" v-show="hasFormPermission('F_FirmLogo')" v-if="disable">
					  <el-form-item :label="$t('企业logo')" prop="F_FirmLogo">
					    <xjr-custom-upload :config="F_FirmLogoConfig" v-model="companiesUserForm.F_FirmLogo"
					      list-type="picture-card" size="small"></xjr-custom-upload>
					  </el-form-item>
					</el-col>
					<el-col :span="12" v-show="hasFormPermission('F_CreditCode')" v-if="disable">
					  <el-form-item :label="$t('统一社会信用代码')" prop="F_CreditCode">
					    <el-input v-model="companiesUserForm.F_CreditCode" placeholder="请输入统一社会信用代码" size="small">
					    </el-input>
					  </el-form-item>
					</el-col>
					<el-col :span="12" v-show="hasFormPermission('fplaceofregistration')">
					  <el-form-item :label="$t('单位登记所在地')" prop="fplaceofregistration">
					    <avue-select-area v-model="companiesUserForm.fplaceofregistration"></avue-select-area>
					  </el-form-item>
					</el-col>
					<el-col :span="12" v-show="hasFormPermission('F_BusinessLicense')" v-if="disable">
					  <el-form-item :label="$t('企业营业执照')" prop="F_BusinessLicense">
					    <xjr-custom-upload :config="F_BusinessLicenseConfig" v-model="companiesUserForm.F_BusinessLicense"
					      list-type="picture-card"></xjr-custom-upload>
					  </el-form-item>
					</el-col>
					<el-col :span="24" __isOnlyLookInput__="hasLookFormPermission('field110229a')" v-if="disable">
					  <el-form-item label-width="0" prop="field110229a">
					    <h2 align='center' style="color:undefined;font-size: 16px;text-align: left"
					      :style="{width: '100%'}">法人信息</h2>
					  </el-form-item>
					</el-col>
					<el-col :span="12" v-show="hasFormPermission('F_LegalPersonName')" v-if="disable">
					  <el-form-item :label="$t('法人姓名')" prop="F_LegalPersonName">
					    <el-input v-model="companiesUserForm.F_LegalPersonName" placeholder="请输入法人姓名" size="small">
					    </el-input>
					  </el-form-item>
					</el-col>
					<el-col :span="12" v-show="hasFormPermission('flegalpersoncertificatetype')" v-if="disable">
					  <el-form-item :label="$t('法人证件类型')" prop="flegalpersoncertificatetype">
					    <el-select v-model="companiesUserForm.flegalpersoncertificatetype" placeholder="请选择法人证件类型" filterable size="small">
					      <el-option v-for="(item, index) in flegalpersoncertificatetypeOptions" :key="index" :label="item.F_ItemName"
					        :value="item.F_ItemValue" :disabled="item.disabled"></el-option>
					    </el-select>
					  </el-form-item>
					</el-col>
					<el-col :span="12" v-show="hasFormPermission('F_LegalPersonCertificateNum')" v-if="disable">
					  <el-form-item :label="$t('证件号码')" prop="F_LegalPersonCertificateNum">
					    <el-input v-model="companiesUserForm.F_LegalPersonCertificateNum" placeholder="请输入证件号码" size="small">
					    </el-input>
					  </el-form-item>
					</el-col>
					<el-col :span="12" v-show="hasFormPermission('F_LegalPersonPhone')" v-if="disable"> 
					  <el-form-item :label="$t('法人手机号')" prop="F_LegalPersonPhone">
					    <el-input v-model="companiesUserForm.F_LegalPersonPhone" placeholder="请输入法人手机号" size="small">
					    </el-input>
					  </el-form-item>
					</el-col>
					<el-col :span="12" v-show="hasFormPermission('F_LegalPersonEmail')" v-if="disable">
					  <el-form-item :label="$t('法人邮箱')" prop="F_LegalPersonEmail">
					    <el-input v-model="companiesUserForm.F_LegalPersonEmail" placeholder="请输入法人邮箱" size="small">
					    </el-input>
					  </el-form-item>
					</el-col>
				</el-form>
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button size="mini" @click="cancelForm('userForm')">{{$t('buttonModule.modalCloseBtn')}}</el-button>
				<el-button size="mini" type="primary" @click="userFormSubmit('userForm')" :loading="flagUser">
					{{flagUser?$t('workFlow.WFMenu.hintSubmit'):$t('buttonModule.modalSureBtn')}}</el-button>
			</span>
		</el-dialog>
		<!-- 功能授权 -->
		<el-dialog v-dialogDrag class="authorizedialog" :title="$t('orgUserManagement.setAutModal.modalTitle')"
			:append-to-body="true" top="9vh" :visible.sync="authorizeVisible" :close-on-click-modal="false" width="80%"
			:before-close="closeAuthorizeDialog">
			<authorize-select-tree ref="authorizeTreeRef" v-if="authorizeVisible" :objectType="objectType"
				:objectId="objectId"></authorize-select-tree>
			<span slot="footer" class="dialog-footer">
				<el-button size="mini" @click="closeAuthorizeDialog">{{$t('buttonModule.modalCloseBtn')}}</el-button>
				<el-button size="mini" type="primary" @click="confirmAuthorizeDialog" :loading="flagUserFunc">
					{{flagUserFunc?$t('workFlow.WFMenu.hintSubmit'):$t('buttonModule.modalSureBtn')}}</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	import MainFixed from "@/page/main/MainFixed";
	import MainContent from "@/page/main/MainContent";
	import OrgImport from "./components/OrgImport.vue";
	import AuthorizeSelectTree from "./components/AuthorizeSelectTree";
	import AppAuthorize from "./components/app/AppAuthorize"; //App功能授权
	import authorizeMixin from "@/mixins/authorize"; //鉴权混入
	import tableOptionMixin from "@/mixins/tableOption"; //table 高度计算
	import displayColumnsMixin from "@/mixins/displayColumns"; //表格展示列显隐保存
	import {
		deepClone,
		FormatTree,
		formValidateNotice
	} from '@/util/util';
	import {
		getLowerDepartment
	} from '@/api/organization/department';
	import {
		getCompaniesUserList,
		getCompaniesDepartments,
		postUser,
		modifyUser,
		deleteUser,
		switchUser,
		resetPassword,
	} from "@/api/organization/user";
	import request from '@/router/axios';
	import {
		getLowerCompanies
	} from "@/api/organization/company";
	import {
		baseUrl
	} from "@/config/env";
	import {
		postAuthorizes
	} from "@/api/organization/index";
	import {
		validateLength,
		validatePhone,
		validateTelePhone,
		validateEmail,
		validateOicq
	} from "@/api/organization/validateFunc";
	export default {
		name: "UserManagement",
		mixins: [authorizeMixin, tableOptionMixin, displayColumnsMixin],
		components: {
			AuthorizeSelectTree,
			MainContent,
			MainFixed,
			OrgImport,
			AppAuthorize
		},
		data() {
			const _this = this;
			var checkPhone = (rule, value, callback) => {
				const phoneReg = /^1[3|4|5|7|8][0-9]{9}$/;
				if (!value) {
					return callback(new Error(this.$t('orgUserManagement.addModal.Hint.errorMobile')));
				}
				setTimeout(() => {
					// Number.isInteger是es6验证数字是否为整数的方法,但是我实际用的时候输入的数字总是识别成字符串
					// 所以我就在前面加了一个+实现隐式转换

					if (!Number.isInteger(+value)) {
						callback(new Error(this.$t('orgUserManagement.addModal.Hint.errorNumber')));
					} else {
						if (phoneReg.test(value)) {
							callback();
						} else {
							callback(new Error(this.$t('orgUserManagement.addModal.Hint.errorFormat')));
						}
					}
				}, 100);
			};
			return {
				flegalpersoncertificatetypeOptions: [],
				flagUser: false,
				flagUserFunc: false,
				Place:'',
				disable:true,
				fixedTitle: this.$t('orgUserManagement.fixedTitle'),
				contentTitle: "用户列表",
				companiesTree: [],
				companiesUser: [],
				companiesDepartments: [],
				flag: false,
				companiesUserForm: {},				
				companyId: "",
				searchParam: {
					Keyword: null,
				},
				defaultProps: {
					// children: "children",
					label: "F_FullName",
				},			
				dialogVisible: false,
				page: {
					pageSize: 20,
					total: 0,
					currentPage: 1,
					layout: "total, prev, pager, next",
				},
				option: {
					highlightCurrentRow: true,
					stripe: false,
					addBtn: false,
					menuWidth: 150,
					border: false,
					page: true,
					index: true,
					indexLabel: this.$t('orgUserManagement.tabNum'),
					align: "center",
					menuAlign: "center",
					delBtn: false,
					editBtn: false,
					column: [{
							sortable: true,
							label: "用户名",
							prop: "F_Account",
							width: "140",
							align: 'left'
						},
						{
							sortable: true,
							label: "手机号",
							prop: "F_Telephone",
							width: "120",
							align: 'left'
						},
						{
							sortable: true,
							label: this.$t('orgUserManagement.tabEnableDisable'),
							prop: "F_EnabledMark",
							width: "140",
							align: 'left',
							formatter: function(row) {
								return row.F_EnabledMark === 0 ? _this.$t('custmerForm.tableDisable') : _this.$t(
									'custmerForm.tableEnable'); //_this.$t()
							}
						},
						{
							sortable: true,
							label: "用户类型",
							prop: "F_UserType",
							width: "120",
							align: 'left'
						},
						{
							sortable: true,
							label: "企业名称",
							prop: "F_FirmName",
							width: "120",
							align: 'left'
						},
						{
							sortable: true,
							label: "单位登记所在地",
							prop: "fplaceofregistration",
							align: 'left'
						}
					],
				},
				rules: {
					F_Account: [{
							required: true,
							message: this.$t('orgUserManagement.addModal.placeholderAccount'),
							trigger: "change"
						},
						{
							validator: validateLength,
							trigger: 'change'
						}
					],
					F_Telephone: [{
						required: true,
						message: '请输入手机号',
						trigger: 'blur',
					}],
					F_Password: [{
							required: true,
							message: this.$t('orgUserManagement.addModal.placeholderPassword'),
							trigger: "blur"
						},
						{
							min: 6,
							max: 16,
							message: this.$t('orgUserManagement.addModal.Hint.passworldLength'),
							trigger: "blur"
						},
					],
					F_FirmName: [{
						required: true,
						message: '请输入企业名称',
						trigger: 'blur',
					}],
					fplaceofregistration: [{
						required: true,
						message: '请选择单位登记所在地',
						trigger: 'change',
					}],
					F_FirmLogo: [{
						required: true,
						message: '上传不能为空',
						trigger: 'change',
					}],
					F_FirmLogoConfig: {
						"showTip": true,
						"fileSize": 2,
						"sizeUnit": "MB",
						"buttonText": "点击上传",
						"disabled": false,
						"accept": ".jpg, .jpeg, .png",
						"multiple": false,
					},
					F_CreditCode: [{
						required: true,
						message: '请输入统一社会信用代码',
						trigger: 'blur',
					}],
					F_BusinessLicense: [{
						required: true,
						message: '上传不能为空',
						trigger: 'change',
					}],
					F_BusinessLicenseConfig: {
						"showTip": true,
						"fileSize": 2,
						"sizeUnit": "MB",
						"buttonText": "点击上传",
						"disabled": false,
						"accept": ".jpg, .jpeg, .png",
						"multiple": false,
					},
					F_LegalPersonName: [{
						required: true,
						message: '请输入法人姓名',
						trigger: 'blur',
					}],
					flegalpersoncertificatetype: [{
						required: true,
						message: '请选择法人证件类型',
						trigger: 'change',
					}],
					F_LegalPersonCertificateNum: [{
						required: true,
						message: '请输入证件号码',
						trigger: 'blur',
					}],
					F_LegalPersonPhone: [{
						required: true,
						message: '请输入法人手机号',
						trigger: 'blur',
					}],
					F_LegalPersonEmail: [{
						required: true,
						message: '请输入法人邮箱',
						trigger: 'blur',
					}],
				},
				authorizeVisible: false,
				objectId: "",
				objectType: 2,
				authorizeChangeData: [],
				departmentDialogVisible: false,
				selectedList: [],
				genderOptions: [{
						value: 0,
						label: this.$t('custmerForm.female'),
					},
					{
						value: 1,
						label: this.$t('custmerForm.male'),
					},
				],
				allDepartmentsList: [],
				defaultDepartmentProps: {
					value: 'F_DepartmentId',
					label: 'F_FullName',
					// children: 'children',
				},
				F_DepartmentId: '',
				appAuthorizeVisible: false,
				treeNode: '',
				treeResolve: {},
				isFocus: false
			};
		},
		async created() {
		},
		watch: {
			dialogVisible: {
				handler: function(curVal, oldVal) {
					if (!curVal) this.isFocus = false
				}
			}
		},
		methods: {
			handleRowDBLClick(row, event) {
				if (this.hasButtonPermission('modify') && this.openDoubleClickEdit) {
					this.editForm(row)
				}
				
			},
			async loadNode(node, resolve) {
				try {
					const id = node.data.F_CompanyId || '0'
					if (id === '0') {
						let res = await getLowerCompanies(id);
						if (res.data.success) {
							this.companiesTree = res.data.data
							if (this.companiesTree.length > 0) {
								this.companyId = res.data.data[0].F_CompanyId;
								this.getDep(this.companyId);
								this.$nextTick(function() {
									this.$refs.cTree.setCurrentKey(this.companyId);
								})
							}
						}
					} else {
						const departmentId = node.data.F_DepartmentId || '0'
						if (node.data.unGetLowerCompanies) {
							let res = await getLowerDepartment(node.data.F_CompanyId, departmentId)
							if (res.data.success) {
								res.data.data.map(item => {
									item['unGetLowerCompanies'] = true
								})
							}
							resolve(res.data.data)
						} else {
							let [res1, res2] = await Promise.all([getLowerDepartment(node.data.F_CompanyId,
								departmentId), getLowerCompanies(node.data.F_CompanyId)])
							let departmentsData = []
							let companiesData = []
							let resolveData = []
							if (res1.data.success) {
								res1.data.data.map(item => {
									item['unGetLowerCompanies'] = true
								})
								departmentsData = res1.data.data
							}
							if (res2.data.success) {
								companiesData = res2.data.data
							}
							let hasDepartmentData = !!departmentsData.length
							let hasCompaniesData = !!companiesData.length
							if (hasDepartmentData && hasCompaniesData) {
								resolveData = [...departmentsData, ...companiesData]
							} else if (!hasDepartmentData && hasCompaniesData) {
								resolveData = companiesData
							} else if (hasDepartmentData && !hasCompaniesData) {
								resolveData = departmentsData
							}
							resolve(resolveData)
						}
					}
				} catch (error) {}
			},
			/* 获取公司用户数据 */
			getUser() {
				let params = {
					limit: this.page.currentPage,
					size: this.page.pageSize,
					Keyword: this.searchParam.Keyword,
				};

				getCompaniesUserList(params).then((res) => {
					this.companiesUser = res.data.data.Rows;
					this.page.total = res.data.data.Total;
				});

			},
			formateParentTree(data) {
				let list = [];
				data.forEach(item => {
					let temp = {
						F_DepartmentId: '',
						F_FullName: "请选择"
					};
					temp.F_DepartmentId = item.F_DepartmentId;
					temp.F_FullName = item.F_FullName;
					list.push(temp);
				});
				return list;
			},
			/* 获取公司部门 */
			getDep(id) {
				getCompaniesDepartments(id).then((res) => {
					const tree = FormatTree(
						res.data.data,
						"F_DepartmentId",
						"F_FullName",
						"children"
					);
					this.companiesDepartments = tree;
				});
			},
			/* 获取证件类型 */
			flegalpersoncertificatetype() {
				axios({
						url: baseUrl + '/data-items/CertificateType/detail',
						method: 'get',
					}).then(res => {
						this.flegalpersoncertificatetypeOptions = res.data.data;
					})
					.catch(error => {
						console.error('数据异常!', error);
					});
			},
			/* 新增用户 */
			openForm() {
				this.flag = true;
				this.companiesUserForm = {
					F_CompanyId: this.companyId,
					F_UserId: "",
					F_Account: "",
					F_EnabledMark:"",
					F_Password: "",				
					F_Telephone: "",
					F_FirmName: "",
					fplaceofregistration: "",
					F_UserType: "",
					F_FirmLogo: "",
					F_CreditCode: "",
					F_BusinessLicense: "",
					F_LegalPersonName: "",
					flegalpersoncertificatetype: "",
					F_LegalPersonCertificateNum:"",
					F_LegalPersonPhone:"",
					F_LegalPersonEmail:"",
				};
				this.dialogVisible = true;
			},
			/* 提交表单 */
			userFormSubmit(formName) {
				this.flagUser = true;
				this.$refs[formName].validate((valid, object) => {
					if (valid) {
						if (this.flag) {
							let reutrnData = deepClone(this.companiesUserForm);
							// let tempJoinStr =reutrnData.F_DepartmentId.join(',');
							// reutrnData.F_DepartmentId = tempJoinStr;
							postUser(reutrnData).then((res) => {
								if (this.showNotify(res, this.$t('workFlow.categoryList.addTitle'))) {
									this.dialogVisible = false;
									this.companiesUserForm = {};
								}
							}).finally(() => {
								this.flagUser = false;
							});
						} else {
							let reutrnData = deepClone(this.companiesUserForm);
							// let tempJoinStr =reutrnData.F_DepartmentId.join(',');
							// reutrnData.F_DepartmentId = tempJoinStr;
							modifyUser(
								reutrnData.F_UserId,
								reutrnData
							).then((res) => {
								if (this.showNotify(res, this.$t('Notice.dialogTitle.Edit'))) {
									this.dialogVisible = false;
									this.companiesUserForm = {};
								}
							}).finally(() => {
								this.flagUser = false;
							});
						}
					} else {
						formValidateNotice(object, this, this.formEnCodeList)
						this.flagUser = false;
					}
				});
			},
			cancelForm(formName) {
				this.dialogVisible = false;
				this.$refs[formName].resetFields();
			},
			/* 关闭弹窗 */
			handleClose(done) {
				// this.companiesUserForm = {};
				done();
				// console.log(this.companiesUserForm)
			},
			/* 重置表单 */
			ruleForm() {
				this.companiesUserForm = {};
			},
			/* 表格单行选中 */
			setCurrent(row) {
				this.$refs.cuTable.setCurrentRow(row);
			},
			/* 编辑弹窗触发 */
			handleCurrentRowChange(val) {
				this.flag = false;
				this.objectId = val.F_UserId;
				this.companiesUserForm.F_UserId = val.F_UserId;
			},
			/* 表格编辑 */
			async editForm(row) {
				let res = await request({
					url: baseUrl + '/t_barin_user_registration/' + row.F_UserId,
					method: "get",
				});
				this.companiesUserForm = res.data.data;
				console.log(res.data.data.F_UserType)
				if(res.data.data.F_UserType == 2){
					this.disable = false;
				}
				if(res.data.data.F_UserType == 1 || res.data.data.F_UserType == 0){
					this.disable = true;
				}
				this.flegalpersoncertificatetype();
				this.flag = false;
				this.dialogVisible = true;				
			},
			/* 表格删除 */
			deleteForm() {
				this.$confirm(this.$t('deletePrompt.promptContent'), this.$t('deletePrompt.promptTitle'), {
						confirmButtonText: this.$t('buttonModule.modalSureBtn'),
						cancelButtonText: this.$t('buttonModule.modalCancelBtn'),
						type: "warning",
					})
					.then(() => {
						deleteUser(this.companiesUserForm.F_UserId).then(() => {
							this.$notify({
								title: this.$t('deletePrompt.successTitle'),
								message: this.$t('deletePrompt.successDeleted'),
								type: "success",
							});
							//删除数组项 by:yk
							this.companiesUser.forEach((item, idx) => {
								try {
									if (item.F_UserId == this.companiesUserForm.F_UserId) {
										this.companiesUser.splice(idx, 1);
										new Error('退出循环');
									}
								} catch (err) {}
							});
						});
					})
					.catch(() => {});
			},

			/* 启用帐户 */
			enableUser() {
				if (
					!this.companiesUserForm.F_UserId ||
					this.companiesUserForm.F_UserId === ""
				) {
					this.$message({
						message: this.$t('deletePrompt.hintSelectData'),
						type: "warning",
					});
					return;
				}
				if (this.companiesUserForm.F_EnabledMark == 1) {
					this.$message({
						message: this.$t('orgUserManagement.Hint.userEnabled'),
						type: "warning",
					});
					return;
				}
				this.$confirm(this.$t('orgUserManagement.Hint.whetherEnable'), this.$t('deletePrompt.promptTitle'), {
					confirmButtonText: this.$t('buttonModule.modalSureBtn'),
					cancelButtonText: this.$t('buttonModule.modalCancelBtn'),
					type: "warning",
				}).then(() => {
					this.switchUser("enable");
				});
			},
			disableUser() {
				if (
					!this.companiesUserForm.F_UserId ||
					this.companiesUserForm.F_UserId === ""
				) {
					this.$message({
						message: this.$t('deletePrompt.hintSelectData'),
						type: "warning",
					});
					return;
				}
				if (this.companiesUserForm.F_EnabledMark == 0) {
					this.$message({
						message: this.$t('orgUserManagement.Hint.userDisabled'),
						type: "warning",
					});
					return;
				}
				this.$confirm(this.$t('orgUserManagement.Hint.whetherDisabled'), this.$t('deletePrompt.promptTitle'), {
					confirmButtonText: this.$t('buttonModule.modalSureBtn'),
					cancelButtonText: this.$t('buttonModule.modalCancelBtn'),
					type: "warning",
				}).then(() => {
					this.switchUser("disable");
				});
			},
			switchUser(val) {
				switchUser(this.companiesUserForm.F_UserId).then((res) => {
					this.showNotify(res, val === "enable" ? this.$t('deletePrompt.Enable') : this.$t(
						'deletePrompt.Disable'));
				});
			},
			/* 重置密码 */
			resetPassword() {
				if (
					!this.companiesUserForm.F_UserId ||
					this.companiesUserForm.F_UserId === ""
				) {
					this.$message({
						message: this.$t('deletePrompt.hintSelectData'),
						type: "warning",
					});
					return;
				}
				this.$confirm(this.$t('orgUserManagement.Hint.whetherResetPassword'), this.$t(
				'deletePrompt.promptTitle'), {
					confirmButtonText: this.$t('buttonModule.modalSureBtn'),
					cancelButtonText: this.$t('buttonModule.modalCancelBtn'),
					type: "warning",
				}).then(() => {
					resetPassword(this.companiesUserForm.F_UserId).then((res) => {
						this.showNotify(res, this.$t('orgUserManagement.Hint.resetPassword'));
					});
				});
			},
			setAuthorize() {
				if (this.objectId === "") {
					this.$message({
						message: this.$t('deletePrompt.hintSelectData'),
						type: "warning",
					});
					return;
				}
				this.authorizeVisible = true;
			},
			closeAuthorizeDialog() {
				this.authorizeVisible = false;
			},
			authorizeChange(data) {
				this.authorizeChangeData = data;
			},
			searchUser() {
				this.getUser();
			},
			searchReset() {
				this.searchParam.Keyword = null;
				this.page.currentPage = 1;
				this.getUser();
			},
			sortChange() {
				this.getUser();
			},
			onPageLoad() {
				this.getUser();
			},
			confirmAuthorizeDialog() {
				this.flagUserFunc = true;
				let obj = this.$refs.authorizeTreeRef.allCheckChange();
				postAuthorizes(this.objectId, this.objectType, obj).then((res) => {
					if (this.showNotify(res, this.$t('orgUserManagement.Hint.setAuthorization'))) {
						this.closeAuthorizeDialog();
					}
				}).finally(() => {
					this.flagUserFunc = false;
				});
			},
			showNotify(res, msg) {
				if (res.data.success) {
					this.getUser();
					this.$notify({
						title: this.$t('deletePrompt.promptTitle'),
						message: msg + this.$t('workFlow.WFMenu.hintSuccess'),
						type: "success",
					});
					return true;
				} else {
					this.$notify({
						title: this.$t('deletePrompt.promptTitle'),
						message: msg + ":" + res.data.msg + "！",
						type: "warning",
					});
					return false;
				}
			},
			openAppAuthorizeDialog() {
				if (this.objectId === "") {
					this.$message({
						message: this.$t("deletePrompt.hintSelectData"),
						type: "warning"
					});
					return;
				}
				this.appAuthorizeVisible = true;
			},
		},
	};
</script>

<style scoped>
	/* css */
	.main-container {
		height: 100%;
		padding: 0 8px;
	}

	.el-form {
		display: flex;
		flex-wrap: wrap;
	}

	.manager-box {
		display: flex;
	}

	div /deep/ .el-form div:nth-child(odd) .el-form-item .el-form-item__label {
		text-align: right;
	}

	.authorizedialog /deep/.el-dialog {
		height: calc(100% - 18vh);
		margin-bottom: 0;
	}

	.authorizedialog /deep/.el-dialog__body {
		height: calc(100% - 114px);
	}

	@media screen and (max-width: 1123px) {
		/deep/ .avue-crud__left {
			margin-left: 5px !important;
			float: left;
			margin-top: 40px;
		}
	}

	div /deep/ .custom-tree-node span {
		font-size: 14px;
		padding-left: 10px;
	}

	div /deep/ .custom-tree-node i {
		font-size: 12px !important;
	}

	.upload-box {
		margin-right: 0px;
	}
</style>
